package com.yztc.orangeentertainment.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.yztc.orangeentertainment.R;
import com.yztc.orangeentertainment.bean.articlecommentall.ArticleCommentAllListBean;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by My on 2016/10/14.
 */
public class ArticleCommentAllAdapter extends RecyclerView.Adapter<ArticleCommentAllAdapter.MyViewHolder> {
    private List<ArticleCommentAllListBean> list;
    private Context context;

    public void setList(List<ArticleCommentAllListBean> list) {
        this.list = list;
    }

    public ArticleCommentAllAdapter(Context context) {
        this.context = context;
    }

    @Override
    public int getItemViewType(int position) {
        if (position == 0) {
            return 1;
        } else {
            return 2;
        }
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (viewType == 1) {
            View view = LayoutInflater.from(context).inflate(R.layout.articlecommentall_item,
                    parent, false);
            return new MyViewHolderTitle(view);
        } else {
            View view = LayoutInflater.from(context).inflate(R.layout.channalarticlecomment_item,
                    parent, false);
            return new MyViewHolderContent(view);
        }
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        if(holder instanceof MyViewHolderContent){
            ((MyViewHolderContent) holder).ivArticlecommentphoto.setImageURI(list.get(position-1)
                    .getUser().getAvatar());
            ((MyViewHolderContent) holder).tvArticlecommentcontentsom.setText(list.get
                    (position-1).getContent());
            ((MyViewHolderContent) holder).tvArticlecommenttime.setText(list.get(position-1).getPublish_time());
            ((MyViewHolderContent) holder).tvArticlecommentnum.setText(list.get(position-1)
                    .getComment_style()+"");
            ((MyViewHolderContent) holder).tvArticlecommentusername.setText(list.get(position-1)
                    .getUser().getName());

        }
    }

    @Override
    public int getItemCount() {
        return list.size() + 1;
    }

    static class MyViewHolder extends RecyclerView.ViewHolder {

        public MyViewHolder(View itemView) {
            super(itemView);
        }
    }

    static class MyViewHolderTitle extends MyViewHolder {

        public MyViewHolderTitle(View itemView) {
            super(itemView);
        }
    }

    static class MyViewHolderContent extends MyViewHolder {
        @InjectView(R.id.iv_articlecommentphoto)
        SimpleDraweeView ivArticlecommentphoto;
        @InjectView(R.id.tv_articlecommentusername)
        TextView tvArticlecommentusername;
        @InjectView(R.id.tv_articlecommenttime)
        TextView tvArticlecommenttime;
        @InjectView(R.id.tv_articlecommentnum)
        TextView tvArticlecommentnum;
        @InjectView(R.id.tv_articlecommentcontentsom)
        TextView tvArticlecommentcontentsom;
        public MyViewHolderContent(View itemView) {
            super(itemView);
            ButterKnife.inject(this, itemView);
        }
    }

}
